
public class Leetcode1601 {
    public static void main(String[] args) {

    }

    public static int maximumRequests(int n, int[][] requests) {
        int max = 0;
        int length = requests.length;
        for (int i = 0; i < (1 << length); i++) {
            int[] count = new int[n];
            int number = 0;
            for (int j = 0; j < length; j++) {
                if (0 != (i & (1 << j))) {
                    --count[requests[j][0]];
                    ++count[requests[j][1]];
                    number++;
                }
            }
            if (isAllZero(count)) {
                max = Math.max(number, max);
            }
        }


        return max;
    }

    private static boolean isAllZero(int[] count) {
        for (int i : count) {
            if (i != 0) {
                return false;
            }
        }

        return true;
    }
}
